package cn.edu.cug.cs.gtl.apps.gepspacex.modeller;


import cn.edu.cug.cs.gtl.apis.ui.modeller.ModellerFrame;
import cn.edu.cug.cs.gtl.apps.gepspacex.modeller.actions.AppExitActionListener;
import cn.edu.cug.cs.gtl.apps.ui.MainApp;

import javax.swing.*;
import java.awt.*;
import java.util.Locale;
import java.util.ResourceBundle;

public class MainWindow extends ModellerFrame {

    JMenu fileMenu = new JMenu("File");
    JMenu editMenu = new JMenu("Edit");
    JMenu dataMenu = new JMenu("Data");
    JMenu modellingMenu = new JMenu("Modelling");
    JMenu analysisMenu = new JMenu("Analysis");
    JMenu viewMenu = new JMenu("View");
    JMenu toolMenu = new JMenu("Tool");
    JMenuItem pluginMenuItem = new JMenuItem("Plugin...");
    JMenu helpMenu = new JMenu("Help");

    JToolBar fileToolBar = new JToolBar("File");
    JToolBar editToolBar = new JToolBar("Edit");
    JToolBar modellingToolBar = new JToolBar("Modelling");
    JToolBar analysisToolBar = new JToolBar("Analysis");
    JToolBar viewToolBar = new JToolBar("View");
    JToolBar toolToolBar = new JToolBar("Tool");
    JToolBar helpToolBar = new JToolBar("Help");


    public MainWindow(MainApp theApp) throws HeadlessException {
        this.theApp = theApp;
    }

    public MainWindow(MainApp theApp, GraphicsConfiguration gc) {
        super(gc);
        this.theApp = theApp;
    }

    public MainWindow(MainApp theApp, String title) throws HeadlessException {
        super(title);
        this.theApp = theApp;
    }

    public MainWindow(MainApp theApp, String title, GraphicsConfiguration gc) {
        super(title, gc);
        this.theApp = theApp;
    }


    @Override
    public JMenu getFileMenu() {
        return fileMenu;
    }

    @Override
    public JMenu getEditMenu() {
        return editMenu;
    }
    public JMenu getDataMenu() {
        return dataMenu;
    }

    @Override
    public JMenu getViewMenu() {
        return viewMenu;
    }

    @Override
    public JMenu getToolMenu() {
        return toolMenu;
    }

    @Override
    public JMenu getHelpMenu() {
        return helpMenu;
    }

    @Override
    public JToolBar getFileToolBar() {
        return fileToolBar;
    }

    @Override
    public JToolBar getViewToolBar() {
        return viewToolBar;
    }

    @Override
    public JToolBar getEditToolBar() {
        return editToolBar;
    }

    @Override
    public JToolBar getToolToolBar() {
        return toolToolBar;
    }

    @Override
    public JToolBar getHelpToolBar() {
        return helpToolBar;
    }

    @Override
    public JMenu getModellingMenu() {
        return modellingMenu;
    }

    @Override
    public JMenu getAnalysisMenu() {
        return analysisMenu;
    }

    @Override
    public JToolBar getModellingToolBar() {
        return modellingToolBar;
    }

    @Override
    public JToolBar getAnalysisToolBar() {
        return analysisToolBar;
    }

    public void initial() {
        initialMenus();

        getContentPane().setLayout(new BorderLayout());
        JComponent ui = getModellerApp().getModel3dUIApp().initializeUI();
        getContentPane().add(ui, BorderLayout.CENTER);
        initialTooBars();

        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    }


    private void initialMenus() {
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);


        ResourceBundle resourceBundle = ResourceBundle.getBundle("app_resource", Locale.getDefault());

        JMenuBar menubar = new JMenuBar();

        fileMenu.setText(resourceBundle.getString("menu.file"));
        menubar.add(fileMenu);

        JMenuItem appExitItem = new JMenuItem(resourceBundle.getString("menu.file.exit"));
        appExitItem.addActionListener(new AppExitActionListener(theApp));
        fileMenu.add(appExitItem);

        editMenu.setText(resourceBundle.getString("menu.edit"));
        menubar.add(editMenu);

        dataMenu.setText(resourceBundle.getString("menu.data"));
        menubar.add(dataMenu);

        modellingMenu.setText(resourceBundle.getString("menu.modelling"));
        menubar.add(modellingMenu);

        analysisMenu.setText(resourceBundle.getString("menu.analysis"));
        menubar.add(analysisMenu);

        viewMenu.setText(resourceBundle.getString("menu.view"));
        menubar.add(viewMenu);

        toolMenu.setText(resourceBundle.getString("menu.tool"));
        menubar.add(toolMenu);

        pluginMenuItem.setText(resourceBundle.getString("menu.tool.plugin"));
        toolMenu.add(pluginMenuItem);

        helpMenu.setText(resourceBundle.getString("menu.help"));
        menubar.add(helpMenu);

        this.setJMenuBar(menubar);
    }

    private void initialTooBars() {
        JPanel toobarPanel = new JPanel(new FlowLayout(0));
        toobarPanel.add(fileToolBar, FlowLayout.LEFT);
        toobarPanel.add(editToolBar, FlowLayout.LEFT);
        toobarPanel.add(modellingToolBar, FlowLayout.LEFT);
        toobarPanel.add(analysisToolBar, FlowLayout.LEFT);
        toobarPanel.add(viewToolBar, FlowLayout.LEFT);
        toobarPanel.add(toolToolBar, FlowLayout.LEFT);
        toobarPanel.add(helpToolBar, FlowLayout.LEFT);

        getContentPane().add(toobarPanel, BorderLayout.NORTH);
    }


}
